--杀戮嗅觉
local shaluxiujue = fk.CreateSkill {
    name = "mcdh_shaluxiujue"
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

shaluxiujue:addEffect(fk.EventPhaseStart,{
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(self) and target == player and player.phase == Player.Play
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local targets = table.map((table.filter(room:getOtherPlayers(player),function(p) return player:canPindian(p)  end)),Util.IdMapper)
        if #targets > 0  then
            local players = room:askToChoosePlayers(player, {
                targets = targets,
                min_num = 1,
                max_num = 1,
                prompt = "#shaluxiujue-choose",
                skill_name = self.name,
                cancelable = true
              })
            if #players > 0 then
                self.cost_data = players[1]
                return true
            end
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local to = self.cost_data
        local pindian = player:pindian({to}, self.name)
        if pindian.results[to].winner then
            local type = {}
            table.insertIfNeed(type,pindian.fromCard.type)
            table.insertIfNeed(type,pindian.results[to].toCard.type)
            room:setPlayerMark(pindian.results[to.id].winner,"@[cardtypes]shaluxiujue-phase",type)
        end
        if pindian.results[to].winner == player then
            room:damage({
                from = player,
                to = to,
                damage = 1,
                skillName = self.name,
            })
        else
            U.askForUseVirtualCard(room, to, "duel", nil, self.name, "#shaluxiujue-use", true, true, false, false, nil, false)
        end
    end
})

shaluxiujue:addEffect('prohibit',{
    prohibit_use = function(self, player, card)
        if player:getTableMark("@[cardtypes]shaluxiujue-phase") ~= {} then
            return  table.contains(player:getTableMark("@[cardtypes]shaluxiujue-phase"),card.type)
        end

    end,
    prohibit_response = function(self, player, card)
        if player:getTableMark("@[cardtypes]shaluxiujue-phase") ~= {} then
            return  table.contains(player:getTableMark("@[cardtypes]shaluxiujue-phase"),card.type)
        end
    end,
})

Fk:loadTranslationTable {
    ["mcdh_shaluxiujue"] = "杀戮嗅觉",
    [":mcdh_shaluxiujue"] = "出牌阶段开始时，你可以与一名角色拼点。赢的角色本阶段不能使用或打出与双方拼点牌类型相同的牌。若你赢，你对其造成1点伤害；若你没赢，其可以视为使用一张【决斗】。",
    ["#shaluxiujue-choose"] = "杀戮嗅觉: 与一名角色拼点",
    ["#mcdh_shaluxiujue_prohibit"] = "杀戮嗅觉",
    ["@[cardtypes]shaluxiujue-phase"] = "杀戮嗅觉",
    ["#shaluxiujue-use"] = "杀戮嗅觉: 视为使用一张【决斗】"
}

return shaluxiujue